package com.ballgame;
import java.util.Arrays;
import java.util.Scanner;
import static java.lang.Math.*;
public class TwoColorBall {
    //定义成员变量，本类都可以用，注意是否静态
    private static int redCount = 0; //定义红球的中奖个数
    private static boolean blueCount = false;
    public static void main(String[] args) {
        int price = 2;//每注金额
        int count = 0;//下注次数
        int redNum[] = new int[6];//数组里有6个空间
        int blueNum = 0;
       /* int[] Num ;//另一种初始方式
        Num = new int[7];*/

        Scanner sc = new Scanner(System.in);//Scanner类  输入文字或数字
         while(true){
             System.out.println("******欢迎进入双色球彩票系统******");
             System.out.println("输入 1 购买彩票");
             System.out.println("输入 2 查看开奖结果");
             System.out.println("输入 3 退出");
             System.out.print("请输入：");
             int input = sc.nextInt();

             switch (input){   //switch()  括号里的值是上面的返回值  而且与 case的值 相照应
                 case 1:
                     System.out.println("请输入购买注数：");
                     count = sc.nextInt();   //客户可以一次下多注
                     System.out.println("机选号码输入 0； 手选号码输入 1；");
                     int begin = sc.nextInt();
                     switch (begin) {
                         case 0:   //机选
                             //红球，从1-33中选6个
                               // int[] choiceRed = new int[6];//选中的红球
                                //int x;
                             for(int j=1;j<=count;j++) {
                                 for (int i = 0; i < redNum.length; i++) {
                                     redNum[i] = (int) (random() * 33) + 1; //(random()*33) 一定要有括号
                                     // System.out.print(redNum[i]+"\t");
                                 }

                                 Arrays.sort(redNum);
                                 //蓝球  1-16 中选一个
                                 blueNum = (int) (random() * 16) + 1;
                                 System.out.println(Arrays.toString(redNum));
                                 System.out.println(blueNum);
                             }
                             System.out.println("购买金额："+count*price);
                             break;

                         case 1:  //手选

                                 for (int j = 1; j <= count; j++) {
                                    A: for (int n = 0; n < 6; n++) {
                                         System.out.println("红球01--33，请输入6个号码：");
                                         System.out.print("第" + (n+1) + "号码");
                                         redNum[n] = sc.nextInt();  //因为数组从0开始计数，所以n必须从0开始，定义时n=0,否则报错
                                         if(redNum[n]<1 && redNum[n]>33) {
                                             System.out.println("输入错误");
                                             n--;
                                             continue A;
                                         }
                                     }

                                     System.out.println("蓝球01--16，请输入1个号码");
                                     blueNum = sc.nextInt();
                                     if(blueNum>=1 && blueNum<=16 ){
                                         System.out.println("输入错误");
                                         continue;
                                     }
                                     System.out.print("第"+j+"注");
                                     System.out.println("红球：" + Arrays.toString(redNum));
                                     System.out.println("蓝球："+blueNum);
                                 }
                             System.out.println("购买金额："+count*price);
                                 break;
                         default:
                             System.out.println("输入错误");

                     }
                 case 2:  //查看开奖结果
                     if(redCount ==6 && blueCount == true){
                         System.out.println("恭喜你中了一等奖");
                     }else if(redCount == 6 && blueCount == false){
                         System.out.println("恭喜你中了二等奖");
                     }else if(redCount == 5&& blueCount ==true){
                         System.out.println("恭喜你中了三等奖");
                     }else if((redCount == 5 && blueCount==false )||(redCount == 4 && blueCount == true)){
                         System.out.println("恭喜你中了四等奖");
                     }else if((redCount == 4 && blueCount == false)||(redCount == 3 && blueCount == true)){
                 System.out.println("恭喜你中了五等奖");
             }else if (blueCount == true){
                         System.out.println("恭喜你中了六等奖");
                     }

                     System.out.println("开奖结果");
                       luckNum();
                     System.out.println("我购买的号码");
                     System.out.println(Arrays.toString(redNum));
                     System.out.println(blueNum);
                       break;
                 case 3:
                     System.out.println("谢谢使用");
                     return;
                 default:
                     System.out.println("请输入1-3");
             }
         }
    }
    //开奖结果
    /* public static void luckNum() {
            int ln[] = new int[6];
            for(int i=0;i<ln.length-1;i++) {
                if (i < 6) {
                    ln[i] = (int) (random() * 33 + 1);
                } else {
                    ln[6] = (int) (random() * 16 + 1);
                }
            }
            System.out.println("开奖结果"+Arrays.toString(ln));

        }*/
    //开奖结果
    public static void luckNum(){
        int[] redLuck = new int[6];
        int blueLuck;
        for(int i=0;i<redLuck.length;i++){
            redLuck[i] = (int)(random()*33+1);
        }
        blueLuck = (int)(random()*16+1);
        Arrays.sort(redLuck);
        System.out.println("红球开奖号码："+Arrays.toString(redLuck));
        System.out.println("蓝球开奖号码："+blueLuck);
    }

       /* public static void luckNum() {
            int ln[] = new int[6];
            for(int i=0;i<ln.length-1;i++) {
                if (i < 6) {
                    ln[i] = (int) (random() * 33 + 1);
                } else {
                    ln[6] = (int) (random() * 16 + 1);
                }
            }
            System.out.println("开奖结果"+Arrays.toString(ln));

        }*/
    // 获奖名次
    //调用上面的方法的参数，将参数写在括号里
    public static void winNum(int[] redLuck,int blueLuck,int[] redNum,int blueNUm){
        for (int p=0;p<6;p++){
            if(redNum[p] == redLuck[p]) {
                redCount++;
            }
        }
        if(blueNUm == blueLuck){
            blueCount = true;
        }
      //  System.out.println(redCount);
      //  System.out.println(blueCount);
    }
}
